<?php

namespace app\common\model;

use think\Model;

class BaseReplyModel extends BaseModel
{
    protected $autoWriteTimestamp = 'datetime';
    // 定义时间戳字段名
    protected $createTime = 'created';
    protected $updateTime = 'updated';
    protected static $config;
    protected static $media;
    protected function wechatConfig(){
        if(self::$config) return self::$config;
        return self::$config = \config("wechat.");
    }

    public function getMedia(){
        $config=$this->wechatConfig();
        if(self::$media) return self::$media;
        return self::$media=new \WeChat\Media($config);
    }

    public function getMenuControl(){
        $config=$this->wechatConfig();
        if(self::$media) return self::$media;
        return self::$media=new \WeChat\Menu($config);
    }

    /**
     * 获取永久素材
     * @param string $media_id
     * @return array|string
     * @throws Exceptions\LocalCacheException
     * @throws InvalidResponseException
     */
    public function getMaterial($media_id)
    {
        $url = "https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=ACCESS_TOKEN";
        return $this->getMedia()->callPostApi($url, ["media_id"=>$media_id]);
    }
}